﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using PortableDeviceApiLib;

namespace ConsoleApplication1CS
{
    class Program
    {
        static void Main(string[] args)
        {
            //
            // Get an instance of the device manager
            //
            PortableDeviceManager devMgr
                = new PortableDeviceManager();

            //
            // Probe for number of devices
            //
            uint cDevices = 1;
            devMgr.GetDevices(null, ref cDevices);

            //
            // Re-allocate if needed
            //
            if (cDevices > 0)
            {
                string deviceIDs = "";
                devMgr.GetDevices(ref deviceIDs, ref cDevices);

                for (int ndxDevices = 0; ndxDevices < cDevices; ndxDevices++)
                {
                    Console.WriteLine("Device[{0}]: {1}",
                            ndxDevices + 1, deviceIDs[ndxDevices]);
                }
            }
            else
            {
                Console.WriteLine("No WPD devices are present!");
            }
            //string str = "            VALUE \"FileVersion\", \"2.0.171.76\"";
            //Regex re = new Regex(@"(\d+)\.(\d+)\.(\d+)\.(\d+)", RegexOptions.Compiled );
            //Match m = re.Match(str);
            //Console.WriteLine(m.Groups[0].Value);
            //foreach (Group g in m.Groups)
            //{
            //    Console.WriteLine(g.Value);
            //}
            FileSystemWatcher myWatcher = new FileSystemWatcher(@"C:\");
            myWatcher.IncludeSubdirectories = true;
            myWatcher.Changed += myWatcher_Changed;
            myWatcher.Created += myWatcher_Changed;
            myWatcher.Deleted += myWatcher_Changed;
            myWatcher.Renamed += myWatcher_Changed;
            myWatcher.EnableRaisingEvents = true;
            while (true)
            {
                Thread.Sleep(500);
            }
        }

        static void myWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.ChangeType + " - " + e.FullPath);
        }

    }
}
